package com.raytoo.common.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.baomidou.mybatisplus.plugins.Page;
import com.raytoo.common.constant.tips.SuccessTip;
import com.raytoo.common.page.PageInfoBT;
import com.raytoo.common.warpper.BaseControllerWarpper;
import com.raytoo.core.support.HttpKit;

public class BaseController {
	
	protected static String SUCCESS = "SUCCESS";
	protected static String ERROR = "ERROR";
	
	protected static String REDIRECT = "redirect:";
	protected static String FORWARD = "forward:";

	/**
	 * 返回状态和信息
	 */
	protected SuccessTip SUCCESS_TIP = new SuccessTip();
	
	protected HttpServletRequest getHttpServletRequest() {
		return HttpKit.getRequest();
	}
	
	protected HttpServletResponse getHttpServletResponse() {
		return HttpKit.getResponse();
	}
	
	protected HttpSession getSession() {
		return HttpKit.getRequest().getSession();
	}
	
	protected HttpSession getSession(Boolean flag) {
		return HttpKit.getRequest().getSession(flag);
	}
	
	protected String getPara(String name) {
		return HttpKit.getRequest().getParameter(name);
	}
	
	protected void setAttr(String name, Object value) {
		HttpKit.getRequest().setAttribute(name, value);
	}
	
	protected Integer getSystemInvokCount() {
		return (Integer) this.getHttpServletRequest().getServletContext().getAttribute("systemCount");
	}
	
	/**
     * 把service层的分页信息，封装为bootstrap table通用的分页封装
     */
    protected <T> PageInfoBT<T> packForBT(Page<T> page) {
        return new PageInfoBT<T>(page);
    }
	
	/**
     * 包装一个list，让list增加额外属性
     */
    protected Object warpObject(BaseControllerWarpper warpper) {
        return warpper.warp();
    }
    
    
}
